package fun.xiefeihong.video.list.conf

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.redis.connection.RedisConnectionFactory
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer

@Configuration
class RedisConf<K, V> {

    @Bean
    RedisTemplate<K, V> redisTemplate(RedisConnectionFactory connectionFactory) {
        def rt = new RedisTemplate<K, V>()
        def serializer = new Jackson2JsonRedisSerializer<V>(Object.class)
        def stringSerializer = new StringRedisSerializer()
        rt.setValueSerializer(serializer)
        rt.setHashValueSerializer(serializer)
        rt.setKeySerializer(stringSerializer)
        rt.setHashKeySerializer(stringSerializer)
        rt.setConnectionFactory(connectionFactory)
        rt
    }

}